package Ep01_Array.Feb22nd_0009;

/**
 * @author Jimmy Zhan WORKSTATION
 * @Date 2023/2/22 9:44
 * 说明：力扣 0009，回文数
 */

public class Mine {
    public static void main(String[] args) {
        Mine m1 = new Mine();
        int x = 1234321;
        boolean isP = m1.isPalindrome(x);
        if(isP){
            System.out.println(x + " is a palindrome.");
        } else {
            System.out.println(x + " is not a palindrome.");
        }
    }
    public boolean isPalindrome(int x) {
        if (x < 0){
            return false;
        } else if (x <= 9){
            return true;
        } else {
            Integer num = x;
            String str1 = num.toString();
            int[] arr1 = new int[str1.length()];
            for(int i=0; i<str1.length(); i++){
                Character ch = str1.charAt(i);
                arr1[i] = Integer.parseInt(ch.toString());
            }
            for(int i=0; i<=arr1.length/2; i++){
                if(arr1[i] != arr1[arr1.length-1-i]){
                    return false;
                }
            }
            return true;
        }
    }
}
